var schedule = require('node-schedule');
const axios = require('axios')
// ,'44620578514@chatroom'
const sendMsgGroup = ['23242808832@chatroom','43174176960@chatroom']
function sendMessageToLoveCat(msg,groupId) {
    return new Promise((resolve, reject) => {
        axios.post('http://120.27.239.10:8090', {
            "event": "SendTextMsg",
            "robot_wxid": "wxid_yysxpev7jofg22",
            "to_wxid": groupId,
            "msg": msg
        }).then(res=>{
            resolve(res.data)
        })
    })
}
function sendImageToLoveCat(url,groupId) {
    console.log(url,'imageUrl')
    return new Promise((resolve, reject) => {
        axios.post('http://120.27.239.10:8090', {
            "success":true,
            "message":"successful!",
            "event": "SendImageMsg",
            "robot_wxid": "wxid_yysxpev7jofg22",
            "to_wxid": groupId,
            "msg": {//消息内容:发送 图片、视频、文件、动态表情都是这个结构
                "url":url,
                "name":'xiaohei.7d3b39eb.png' //name参数必须要有否则不会发送
            }
        }).then(res=>{
            resolve(res.data)
        })
    })
}
//给部署在电脑上的机器人通过frp单独发消息
function sendMessageToCCRobot(msg) {
    return new Promise((resolve, reject) => {
        axios.post('http://42.193.174.155:8088', {
            "event": "SendTextMsg",
            "robot_wxid": "wxid_rip4wd2tebi822",
            "to_wxid": '43602889510@chatroom',
            "msg": msg
        }).then(res=>{
            resolve(res.data)
        })
    })
}
function sendImageToCCRobot(url) {
    console.log(url,'imageUrl')
    return new Promise((resolve, reject) => {
        axios.post('http://42.193.174.155:8088', {
            "success":true,
            "message":"successful!",
            "event": "SendImageMsg",
            "robot_wxid": "wxid_rip4wd2tebi822",
            "to_wxid": '43602889510@chatroom ',
            "msg": {//消息内容:发送 图片、视频、文件、动态表情都是这个结构
                "url":url,
                "name":'xiaohei.7d3b39eb.png' //name参数必须要有否则不会发送
            }
        }).then(res=>{
            resolve(res.data)
        })
    })
}
// const rule = new schedule.RecurrenceRule();
// rule.second = 10;
 function  newsCycleTask() {
    async function circleSendMsg() {
        for(let i =0;i<sendMsgGroup.length;i++){
            await sendMessageToLoveCat(new Date().toLocaleDateString()+'的每日新闻',sendMsgGroup[i])
            await sendImageToLoveCat('https://api.03c3.cn/zb/',sendMsgGroup[i])
        }
    }
    async function sendCCMsg(){
        await sendMessageToCCRobot(new Date().toLocaleDateString()+'的每日新闻')
        await sendImageToCCRobot('https://api.03c3.cn/zb/')
    }
    schedule.scheduleJob('0 30  9 * * *', ()=>{
        sendCCMsg()
        circleSendMsg()
    });
   
}

module.exports = newsCycleTask